#nao é um exercicio do livro, apenas experimentos feitos interativamente:

class Factorial(object):
    def __init__(self, n):
        self.n = n
        self.product = 1
        self.counter = 1
    
    def __iter__(self):
        while self.counter <= self.n:
            self.product *= self.counter
            self.counter += 1
            yield self.product
        raise StopIteration
    
    def result(self):
        for bla in self: pass
        return self.product

#recursive oneliner:
factorial = lambda n: 1 if n == 1 else n * factorial(n - 1)

        
#statefull function:
def factorial(n):
    product = 1
    while n:
        product *= n
        n -= 1
    return product

    
    
    
    